package com.gitee.wsl.ext.number

import kotlin.math.ln


/** @return the logarithm of value with base a
 */
fun log(a: Float, value: Float): Float {
    return (ln(value.toDouble()) / ln(a.toDouble())).toFloat()
}

/** @return the logarithm of value with base 2
 */
fun log2(value: Float): Float {
    return log(2f, value)
}

fun ilog2(v: Int): Int = kotlin.math.log2(v.toDouble()).toInt()

fun ilog2Ceil(v: Int): Int = kotlin.math.ceil(kotlin.math.log2(v.toDouble())).toInt()
